package org.example.concurrentUtils;

import org.example.utils.Sleeper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ZhengDp
 * @Date 2023/2/20 22:15
 */
@RestController
public class TestCountDownLatchController {

    @GetMapping("/order/{id}")
    public Map<String,Object> order(@PathVariable int id){
        HashMap<String,Object> map = new HashMap<>();

        map.put("id",id);
        map.put("total","2300.00");
        Sleeper.sleep(2000);
        return map;
    }

    @GetMapping("/product/{id}")
    public Map<String,Object> product(@PathVariable int id ) {
        HashMap<String,Object> result = new HashMap<>();
        if ( id == 1) {
            result.put("name","小爱音响");
            result.put("price",300);
        }else if ( id == 2 ){
            result.put("name","小米手机");
            result.put("price",2000);
        }
        result.put("id",id);
        Sleeper.sleep(1000);
        return result;
    }

    @GetMapping("/logistics/{id}")
    public Map<String,Object> logistics(@PathVariable int id) {
        HashMap<String,Object> result = new HashMap<>();
        result.put("id",id);
        result.put("name","中通快递");
        Sleeper.sleep(2000);
        return result;
    }

}
